/*
 * *
 *  * Created with IntelliJ RustRover.
 *  * Description:
 *  * Copyright Author: ZhenYi
 *  * DateTime: 2024/2/14 下午5:10
 *
 */

use salvo::{Depot, handler, Request, Response};
use salvo::http::StatusCode;
use crate::utensil::cookie_local::LocalCookie;

/// local 获取当前用户信息
/// 不需要任何输入，即使你输入了也不会被使用
/// 只需要在请求头中携带Cookie即可
#[handler]
pub async fn local(req: &mut Request, depot: &mut Depot, res: &mut Response){
    let rc = depot.obtain::<LocalCookie>().unwrap();
    let cookie = req.cookie("Cookie");
    match cookie {
        Some(c) => {
            let model = rc.get_local(c.clone()).await;
            res.status_code(StatusCode::ACCEPTED).render(model);
        },
        None => {
            res.status_code(StatusCode::IM_USED).render("{\"Error\":\"Cookie not found\"}");
        }
    }
}